// Common admin javascripts can go here (used by more than one component/plugin).
function PopupPic(sPicURL) { 
window.open( "image-window.html?"+sPicURL, "",  
"resizable=1,HEIGHT=200,WIDTH=200"); 
} 

function LoadStatusWin() { 
UploadFile.style.display = "None";
UploadFileStatus.style.display = "Block";
}

function expandcollapse(divname,imgname,imgpath) {
	if(document.getElementById(divname).style.display == "none") {
	document.getElementById(divname).style.display = "block";
	setCookie(divname,1,1);
	document.getElementById(imgname).src = imgpath + 'collapse.gif';
		if (document.getElementById('expandcollapse_msg')) {
		document.getElementById('expandcollapse_msg').style.display = "none";
		}	
	}
	else {
	document.getElementById(divname).style.display = "none";
		setCookie(divname,0,1);
	document.getElementById(imgname).src = imgpath + 'expand.gif';
		if (document.getElementById('expandcollapse_msg')) {
		document.getElementById('expandcollapse_msg').style.display = "block";
		}	
	}	
}

function simpleexpandcollapse(divname) {
	if(document.getElementById(divname).style.display == "none") {
	document.getElementById(divname).style.display = "block";
	}
	else {
	document.getElementById(divname).style.display = "none";	
	}	
}

function collapse(divname) {
	document.getElementById(divname).style.display = "none";
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

/* function to open the filebrowser in a popup window */
function OpenFileBrowser( url )
{
	var winwidth = 600;
	var winheight = 450;
	var iLeft = ( screen.width  - winwidth ) / 2 ;
	var iTop  = ( screen.height - winheight ) / 2 ;

	var sOptions = "toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=1,location=no,menubar=no,directories=no,personalbar=no" ;
	sOptions += ",width=" + winwidth ;
	sOptions += ",height=" + winheight ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;

	window.open( url, 'FileBrowserWindow', sOptions ) ;
}

/* Used with image browser/selector */
function SetUrl(fileurl,imagename,imgname,ffield,fname) 
{
 	document.getElementById(imgname).src = fileurl ;
 	document.getElementById(ffield).value = imagename ;
}

function mycallback() { 
}

function myerror() { 
}

/* used for checking all checkboxes */
function checkAll2(checkname,exby)
{
alert(checkname.length);
for (i = 0; i < checkname.length; i++)
checkname[i].checked = exby.checked? true:false;
alert(i);
}

/* scripts that can be used to toggle the row color on an onclick and check a checkbox */
function togglerow(id,cbox) {
 if(document.getElementById(id).className == 'menu_row_over2') {
 	document.getElementById(id).className = 'menu_row_over';
	document.getElementById(cbox).checked = true;
 }
 else {
  	document.getElementById(id).className = 'menu_row_over2';
	document.getElementById(cbox).checked = false;
 }
}

/* row hover effect */
function rowhoverin(id) {
 if(document.getElementById(id).className == 'menu_row_over') {
 	document.getElementById(id).className = 'menu_row_over';
 }
 else {
  	document.getElementById(id).className = 'menu_row_over2';
 }
}

function rowhoverout(id) {
 if(document.getElementById(id).className == 'menu_row_over') {
 	document.getElementById(id).className = 'menu_row_over';
 }
 else {
  	document.getElementById(id).className = 'menu_row';
 }
}

/* a script to resize divs when window is resized */
function resizeall() {
var NS = (navigator.appName=="Netscape")?true:false; 
iWidth = (NS)?window.innerWidth:document.body.clientWidth; 
iHeight = (NS)?window.innerHeight:document.body.clientHeight; 
mainwidth = iWidth - 100;
document.getElementById('main_div').style.width = mainwidth + 'px';
}

/* for redirects */
function delayer(pageurl){
    window.location = pageurl;
}

/* for image editor */
$(function(){

	$('#image_editing').Jcrop({
		aspectRatio: 0,
		onSelect: updateCoords
	});

});

function updateCoords(c)
{
	$('#x').val(c.x);
	$('#y').val(c.y);
	$('#w').val(c.w);
	$('#h').val(c.h);
};

function checkCoords()
{
	if (parseInt($('#w').val())) document.getElementById('cropform').submit(); return true;
	alert('Please select a crop region then press submit.');
	return false;
};

function confirmclose() {
	var agree=confirm("Are you sure you want to close?  Changes will be lost!");
	if (agree) {
		location.replace('index.cfm?c=imagelibrary'); 
		}
}
/* end image editor scripts */

/*function used in various components that resets the dialog box to the default one that is created on the page this is is called from */
function resetbox() {
	document.getElementById('dialog').innerHTML = document.getElementById('defaultdialog').innerHTML;
}

